const request = (url, params) => {
  return new Promise((resolve, reject) => {
    window.fetch(
      `https://conduit.productionready.io/api/users${url}`,
      {
        body: JSON.stringify(params),
        headers: {
          "content-type": "application/json",
        },
        method: "POST",
        mode: 'cors'
      }
    ).then((res) => {
      return res.json()
    }).then((res) => {
      if (res.errors) {
        throw res.errors
      }
      resolve(res)
    }).catch((error) => {
      reject(error);
    });
  })
}

export default request